package com.altersoftware.hotel.dao;

import java.util.List;

import org.apache.ibatis.annotations.*;

import com.altersoftware.hotel.entity.PermissionDO;

/**
 * @author czy@win10
 * @dte 2020/1/22 17:42
 */
@Mapper
public interface PermissionDAO {

    /**
     * 插入
     *
     * @param permissionDO
     */
    @Insert(" INSERT INTO tb_permission (permission_number, permission_name, permission_to, create_time, modify_time ) "
        +
        "VALUES(#{id}, #{name}, #{resource}, NOW(), NOW()) ")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "permission_number")
    void insert(PermissionDO permissionDO);

    /**
     * Id查询权限
     *
     * @param id
     */
    @Select(" select permission_number, permission_name, permission_to, create_time, modify_time"
        +
        " from tb_permission where permission_number=#{id} ")
    @Results({
        @Result(property = "id", column = "permission_number"),
        @Result(property = "name", column = "permission_name"),
        @Result(property = "resource", column = "permission_to"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    PermissionDO getPermissionById(long id);

    /**
     * 名称查找权限
     *
     * @param name
     */
    @Select(" select permission_number, permission_name, permission_to, create_time, modify_time"
        +
        " from tb_permission where permission_name=#{name} ")
    @Results({
        @Result(property = "id", column = "permission_number"),
        @Result(property = "name", column = "permission_name"),
        @Result(property = "resource", column = "permission_to"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    PermissionDO getPermissionByName(@Param("name") String name);

    /**
     * 展示所有权限
     *
     */
    @Select("select * from tb_permission")
    @Results({
        @Result(property = "id", column = "permission_number"),
        @Result(property = "name", column = "permission_name"),
        @Result(property = "resource", column = "permission_to"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    List<PermissionDO> getList();

    /**
     * id删除权限
     * 
     */
    @Delete("DELETE FROM tb_permission WHERE permission_number=#{id}")
    void deleteById(long id);

    /**
     * 更新权限
     * 
     */
    @Update("update tb_permission  set permission_name=#{name}, permission_to=#{resource}, modify_time=now()"
        +
        "where permission_number=#{id}")
    int update(PermissionDO staffDO);

}
